'''
Created on May 5, 2013

@author: Artur
'''

import urllib.request as urlreq


def GetElem(page_str, startText, endText):
    startPos = page_str.find(startText)
    endPos = page_str.find(endText, startPos)
    return page_str[startPos+len(startText):endPos]


def TestProxy():
    #proxy = "61.233.25.166:80"
    proxy = "199.15.248.179:3128"
    
    proxies = {"http":"http://%s" % proxy}
    url = "http://whatismyipaddress.com"
    headers={'User-agent' : 'Mozilla/5.0'}
    
    proxy_support = urlreq.ProxyHandler(proxies)
    opener = urlreq.build_opener(proxy_support, urlreq.HTTPHandler(debuglevel=1))
    urlreq.install_opener(opener)
    
    req = urlreq.Request(url, None, headers)
    html = urlreq.urlopen(req).read()
    
    print( GetElem(str(html), '<span class="ip blue">', '</span>') )


def GetProxyList():
    url = 'http://www.freeproxylists.net/?c=US&pr=HTTPS&a[]=1'
    
    list = str(urlreq.urlopen(url).read())
    
    print(list)
    
    
GetProxyList()
